package response;

import core.Constants;
import core.GamePacket;
import core.GameQuestion;
import java.util.List;

/**
 * @author brian
 */
public class ResponseQuestionLog extends GameResponse {

    private List<GameQuestion> questionLog;
    private int duration;

    public ResponseQuestionLog() {
        code = Constants.SMSG_QUESTION_LOG;
    }

    public void setQuestionLog(List<GameQuestion> questionLog) {
        this.questionLog = questionLog;
    }

    public List<GameQuestion> getQuestionLog() {
        return questionLog;
    }

    @Override
    public byte[] createResponse() {
        GamePacket packet = new GamePacket(code);

        /*Protocol:
         * (int) numResults, [(short) id, (short) type, (String) topic, (String) text,
         * (String) preparedOptions, (boolean) status, (short) choice, (short) answer]*
         */
        packet.addUint32(questionLog.size());
        for(GameQuestion question : questionLog) {
            packet.addUint16(question.getID());
            packet.addUint16(question.getType());
            packet.addString(question.getTopic());
            packet.addString(question.getText());
            packet.addString(question.getPreparedOptions());
            packet.addBool(question.getStatus());
            packet.addUint16(question.getChoice());
            packet.addUint16(question.getAnswer());
        }       

        return packet.getBytes();
    }
}
